 ///////////////////
//BLOCK FONCTIONS METIER
///////////////////
//function saisirContact(p_codeDate, p_reponse, p_message)
//function envoyerAvert() 
//function envoyerRapports()
//function envoyerRelanceSupDeb()

///////////////////
//BLOCK FONCTIONS PRESENTATION
///////////////////
//getHTMLExpireToday(tabExpireToday)
//getHTMLExpire20h(tabExpire20h)
//function getHtmlSuiviKO(p_user)
//function AfficherFreshData() 
//function intToTimeChar(intTime) 
//function getHtmlAvert()
//function getHTMLTab5(tabResultatTab5) 

///////////////////
//BLOCK FONCTIONS TECHNIQUES
///////////////////
//function inputMoisEnCours(p_champs1, p_champs2) 
//function inputMoisEnCoursRH(p_champs1, p_champs2)

///////////////////
//BLOCK FONCTIONS AJAX JS/PHP/MYSQL
///////////////////
//function getExpireToday()
//function getTabLive(p_strDate)
//function getTabRapportRHuser(p_user)
//function AfficherExpiration(p_idtoc)
//function getInfoToc(p_idtoc) 
//function getDateExpire(p_priorite, p_statut, p_ecoule, p_lefttime)
//function addStat(user, page, action)
//function getTabUsers(date) 
//function getTabUsers_lv1() 
//function gettabResultatTab5()

//---------------------------------------------------------

///////////////////
//BLOCK VARIABLE GLOBAL
///////////////////


///////////////////
//BLOCK FONCTIONS METIER
///////////////////	
/**
 * envoyerAvert
 * 
 */
function envoyerAvert() {
    try {
        var tabAvert = getTabAvert();

        if(tabAvert.length > 0){
            var html = getHtmlAvert(tabAvert);

            var email_mail_ori = "";
            var email_labelle_ori = "";
            var email_mail_reply = "";
            var email_labelle_reply = "";
            var email_mails_dest = "";
            var email_mails_copy = "";
            var email_mails_cache = "";
            var message_txt = "";
            var message_html = "";
            var sujet = "";

            email_mail_ori = "oda.service.mail@cgi.com";
            email_labelle_ori = "Service Mail ODA";
            email_mail_reply = "oda.service.mail@cgi.com";
            email_labelle_reply = "Service Mail ODA";

            var returnSql = new Array();
            var sql = "SELECT mail FROM `tab_utilisateurs` a, tab_service_mail_dest b WHERE 1=1 AND a.code_user = b.code_user AND b.id_type_mail = 1 AND nivo = 1";
            returnSql = getSQL(sql);
            for (var indice in returnSql) {
                email_mails_dest += returnSql[indice]+",";
            }

            var returnSql = new Array();
            var sql = "SELECT mail FROM `tab_utilisateurs` a, tab_service_mail_dest b WHERE 1=1 AND a.code_user = b.code_user AND b.id_type_mail = 1 AND nivo = 2";
            returnSql = getSQL(sql);
            for (var indice in returnSql) {
                email_mails_copy += returnSql[indice]+",";
            }

            var returnSql = new Array();
            var sql = "SELECT mail FROM `tab_utilisateurs` a, tab_service_mail_dest b WHERE 1=1 AND a.code_user = b.code_user AND b.id_type_mail = 1 AND nivo = 3";
            returnSql = getSQL(sql);
            for (var indice in returnSql) {
                email_mails_cache += returnSql[indice]+",";
            }

            message_txt = "Anomalie avec le support du HTML.";

            message_html = "<html><head></head><body>"+html+"</body></html>";

            var labDate = getParameter("last_scan_inventaire_live");
            sujet = "[ODA]Tickets non affect\351s en priorit\351 P1 ou P2, relev\351 au "+labDate+".";

            send_mail(email_mail_ori,email_labelle_ori,email_mail_reply,email_labelle_reply,email_mails_dest,email_mails_copy,email_mails_cache,message_txt,message_html,sujet);
        }
    }
    catch (er) {
            log(0, "ERROR(envoyerAvert):" + er.message);
    }
}

function envoyerRapports() {
	try {
		var html = "";
			
		var labDate = getStrDateFR();
		
		html += "<p>Liste des tickets P1 & P2 qui expireront aujourd'hui : </p>";
		
		var tabExpireToday = new Array();
		tabExpireToday = getExpireToday();

		innerHtmlExpireToday = getHTMLExpireToday(tabExpireToday);
		
		html += innerHtmlExpireToday;
		
		html += "<p>Liste des tickets P3 & P4 qui expireront aujourd'hui : </p>";
		
		var tabExpire20h = new Array();
		tabExpire20h = getExpire20h();

		innerHtmlExpire20h = getHTMLExpire20h(tabExpire20h);
		
		html += innerHtmlExpire20h;
		
		var htmlTab5 = "";
		var tabResultatTab5 = new Array();
		
		tabResultatTab5 = gettabResultatTab5();
		
		htmlTab5 = getHTMLTab5(tabResultatTab5);
		
		html += htmlTab5;
			
		var email_mail_ori = "";
		var email_labelle_ori = "";
		var email_mail_reply = "";
		var email_labelle_reply = "";
		var email_mails_dest = "";
		var email_mails_copy = "";
		var email_mails_cache = "";
		var message_txt = "";
		var message_html = "";
		var sujet = "";
		
		email_mail_ori = "oda.service.mail@cgi.com";
		email_labelle_ori = "Service Mail ODA";
		email_mail_reply = "oda.service.mail@cgi.com";
		email_labelle_reply = "Service Mail ODA";
		
		var returnSql = new Array();
		var sql = "SELECT mail FROM `tab_utilisateurs` a, tab_service_mail_dest b WHERE 1=1 AND a.code_user = b.code_user AND b.id_type_mail = 4 AND nivo = 1";
		returnSql = getSQL(sql);
		for (var indice in returnSql) {
			email_mails_dest += returnSql[indice]+",";
		}
		
		var returnSql = new Array();
		var sql = "SELECT mail FROM `tab_utilisateurs` a, tab_service_mail_dest b WHERE 1=1 AND a.code_user = b.code_user AND b.id_type_mail = 4 AND nivo = 2";
		returnSql = getSQL(sql);
		for (var indice in returnSql) {
			email_mails_copy += returnSql[indice]+",";
		}
		
		var returnSql = new Array();
		var sql = "SELECT mail FROM `tab_utilisateurs` a, tab_service_mail_dest b WHERE 1=1 AND a.code_user = b.code_user AND b.id_type_mail = 4 AND nivo = 3";
		returnSql = getSQL(sql);
		for (var indice in returnSql) {
			email_mails_cache += returnSql[indice]+",";
		}
		
		message_txt = "Anomalie avec le support du HTML.";
		
		message_html = "<html><head></head><body>"+html+"</body></html>";
		
		sujet = "[ODA]Rapports du "+labDate+".";
		
		send_mail(email_mail_ori,email_labelle_ori,email_mail_reply,email_labelle_reply,email_mails_dest,email_mails_copy,email_mails_cache,message_txt,message_html,sujet);
	}
	catch (er) {
		log(0, "ERROR(envoyerRapports):" + er.message);
	}
}

///////////////////
//BLOCK FONCTIONS PRESENTATION
///////////////////
function getHTMLExpireToday(tabExpireToday) {
	try {
		var strRetour = "";
		
		strRetour += "<table BORDER=\"1\" style=\"font-size:14px;background-color:white;text-shadow: none;\">";
		strRetour += "<TR>";
		strRetour += "<TH> <a href=\"#\" title=\"Nom ticket\">Nom ticket</a></TH>";
		strRetour += "<TH> <a href=\"#\" title=\"Priorit&eacute;\">Priorit&eacute;</a></TH>";
		strRetour += "<TH> <a href=\"#\" title=\"Responsable\">Responsable</a></TH>";
		strRetour += "<TH> <a href=\"#\" title=\"Date cr&eacute;ation\">Date cr&eacute;ation</a></TH>";
		strRetour += "<TH> <a href=\"#\" title=\"Date d'expiration\">Expire</a></TH>";
		strRetour += "<TH> <a href=\"#\" title=\"Libell&eacute;\">Libell&eacute;</a></TH>";
		strRetour += "</TR>";

		for (var indice in tabExpireToday) {
			strRetour += "<TR>";
			strRetour += "<TD >&nbsp;<a target=\"_new\" href=\"http://10.197.68.30:4000/AutoDiseWeb/automate/popupModule.jsp?modType=SIG_SIG&modCode=" + tabExpireToday[indice][0] + "\">" + tabExpireToday[indice][0] + "</a> </TD>";
			strRetour += "<TD >&nbsp;" + tabExpireToday[indice][1] + " </TD>";
			strRetour += "<TD >&nbsp;" + tabExpireToday[indice][2] + " </TD>";
			strRetour += "<TD >&nbsp;" + tabExpireToday[indice][3] + " </TD>";
			strRetour += "<TD >&nbsp;" + getDateExpire(null, null, null, tabExpireToday[indice][6]) + " </TD>";
			strRetour += "<TD style=\"width: 300px;\" >&nbsp;" + tabExpireToday[indice][4] + " </TD>";
			strRetour += "</TR>";
		}

		strRetour += "</table>";
		strRetour += "<br>";
		strRetour += "<br>";

		return strRetour;
	}
	catch (er) {
		log(0, "ERROR(getHTMLExpireToday):" + er.message);
	}
}

function getHTMLExpire20h(tabExpire20h) {
	try {
		var strRetour = "";
		
		strRetour += "<table BORDER=\"1\" style=\"font-size:14px;background-color:white;text-shadow: none;\">";
		strRetour += "<TR>";
		strRetour += "<TH> <a href=\"#\" title=\"Nom ticket\">Nom ticket</a></TH>";
		strRetour += "<TH> <a href=\"#\" title=\"Priorit&eacute;\">Priorit&eacute;</a></TH>";
		strRetour += "<TH> <a href=\"#\" title=\"Responsable\">Responsable</a></TH>";
		strRetour += "<TH> <a href=\"#\" title=\"Date cr&eacute;ation\">Date cr&eacute;ation</a></TH>";
		strRetour += "<TH> <a href=\"#\" title=\"Date d'expiration\">Expire</a></TH>";
		strRetour += "<TH> <a href=\"#\" title=\"Libell&eacute;\">Libell&eacute;</a></TH>";
		strRetour += "</TR>";

		for (var indice in tabExpire20h) {
			strRetour += "<TR>";
			strRetour += "<TD >&nbsp;<a target=\"_new\" href=\"http://10.197.68.30:4000/AutoDiseWeb/automate/popupModule.jsp?modType=SIG_SIG&modCode=" + tabExpire20h[indice][0] + "\">" + tabExpire20h[indice][0] + "</a> </TD>";
			strRetour += "<TD >&nbsp;" + tabExpire20h[indice][1] + " </TD>";
			strRetour += "<TD >&nbsp;" + tabExpire20h[indice][2] + " </TD>";
			strRetour += "<TD >&nbsp;" + tabExpire20h[indice][3] + " </TD>";
			strRetour += "<TD >&nbsp;" + getDateExpire(null, null, null, tabExpire20h[indice][6]) + " </TD>";
			strRetour += "<TD style=\"width: 300px;\" >&nbsp;" + tabExpire20h[indice][4] + " </TD>";
			strRetour += "</TR>";
		}

		strRetour += "</table>";
		strRetour += "<br>";
		strRetour += "<br>";

		return strRetour;
	}
	catch (er) {
		log(0, "ERROR(getHTMLExpire20h):" + er.message);
	}
}

function getHtmlSuiviKO(p_user) {
	try {
		var tab = new Array();
		tab = getTabRapportRHuser(p_user);
		//[X][0] = date
		//[X][1] = responsable
		//[X][2] = total
		
		var strRetour = "";
		
		if(tab.length > 0){
					
			strRetour += "<center>";
			strRetour += "<br>";
			strRetour += "<img border=0 src=\"img/mini_attention.png\" /> Vous n'avez pas rempli enti&egrave;rement votre suivi hebdomadaire.";
			strRetour += "<br>";
			
			strRetour += "			<table cellpadding=\"0\" cellspacing=\"0\" border=1 style=\"font-size:14px;background-color:white;\">";
			
			strRespon = "";
			
			strRetour += "				<tr>";
			strRetour += "					<td style=\"width: 100px;text-align:center;\">";
			strRetour += "						Responsable";
			strRetour += "					</td>";
			strRetour += "					<td style=\"width: 150px;text-align:center;\">";
			strRetour += "						Non compl&eacute;t&eacute;";
			strRetour += "					</td>";
			
			for (var indice in tab) {
				if(strRespon != tab[indice][1]){
					strRetour += "					</td>";
					strRetour += "				</tr>";
					strRespon = tab[indice][1];
					strRetour += "				<tr>";
					strRetour += "					<td style=\"width: 100px;text-align:center;\">";
					strRetour += "						"+tab[indice][1]+"";
					strRetour += "					</td>";
					strRetour += "					<td style=\"width: 150px;text-align:center;font-size:10px;\">";
				}
				strRetour += "				"+tab[indice][0]+"("+tab[indice][2]+")<br>";
			}
			strRetour += "					</td>";
			strRetour += "				</tr>";
			strRetour += "			</table>";
			strRetour += "</center>";
			
		}
		

        return strRetour;
	}
	catch (er) {
		log(0, "ERROR(getHtmlSuiviKO):" + er.message);
	}
}

function getHtmlAvert(p_tabAvert) {
	try {
		var strResponse = "";
		
		strResponse += "<table BORDER=\"1\">";
		strResponse += "<thead>";
		strResponse += "<TR>";
		strResponse += "<TH> <a href=\"#\" title=\"Nom ticket\">Nom ticket</a></TH>";
		strResponse += "<TH> <a href=\"#\" title=\"Priorit&eacute;\">Priorit&eacute;</a></TH>";
		strResponse += "<TH> <a href=\"#\" title=\"Responsable\">Responsable</a></TH>";
		strResponse += "<TH> <a href=\"#\" title=\"Date cr&eacute;ation\">Date cr&eacute;ation</a></TH>";
		strResponse += "<TH> <a href=\"#\" title=\"Libell&eacute;\">Libell&eacute;</a></TH>";
		strResponse += "</TR>";
		strResponse += "</thead>";
		strResponse += "<tbody>";

		for (var indice in p_tabAvert) {
			strResponse += "<TR>";
			strResponse += "<TD><a target=\"_new\" href=\"http://10.197.68.30:4000/AutoDiseWeb/automate/popupModule.jsp?modType=SIG_SIG&modCode=" + p_tabAvert[indice][0] + "\">" + p_tabAvert[indice][0] + "</a></TD>";
			strResponse += "<TD>" + p_tabAvert[indice][1] + "</TD>";
			strResponse += "<TD>" + p_tabAvert[indice][2] + "</TD>";
			strResponse += "<TD>" + p_tabAvert[indice][3] + "</TD>";
			strResponse += "<TD style=\"width: 500px;\" >" + p_tabAvert[indice][4] + " </TD>";
			strResponse += "</TR>";
		}

		strResponse += "</tbody>";
		strResponse += "</table>";
		
		return strResponse;
	}
	catch (er) {
		log(0, "ERROR(getHtmlAvert):" + er.message);
	}
}

function intToTimeChar(intTime) {
    try {
        if ((!isNaN(intTime)) & (intTime != 0)) {
            nbMinute = Math.round(intTime) % 60;
            nbHeure = (Math.round(intTime) - nbMinute) / 60;
            nbHeure = nbHeure % 10;
            nbJour = (Math.round(intTime) - (nbHeure * 60) - nbMinute) / 600;
            strTime = nbJour + "j" + nbHeure + "h" + nbMinute;
        } else {
            strTime = "0";
        }
        return strTime;
    }
    catch (er) {
        log(0, "ERROR(intToTimeChar):" + er.message);
        return "xjxhx";
    }
}

//get html pour rapport stock
function getHTMLTab5(tabResultatTab5) {
	try {
		var indiceConfiance = Math.round((1 / parseFloat(tabResultatTab5[0][0]))*100);
		
		var strRetour = "";
		
		strRetour += "<br>";
		strRetour += "Indice de confiance :  "+indiceConfiance+"%\n";
		strRetour += "<br>";
		strRetour += "<br>";
		strRetour += "I - ETAT DU STOCK<br>";
		strRetour += "<table style=\"text-align: left; width: 400;text-shadow: none;color: rgb(0, 0, 0);\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">";
		strRetour += "  <tbody>";
		strRetour += "	<tr>";
		strRetour += "	  <td colspan=\"3\" style=\"text-align: center;background-color: DarkGray;\"><b>Tickets en stock</b></td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: center;background-color: DarkGray;\"><b>Statut</b></td>";
		strRetour += "	  <td colspan=\"2\" style=\"text-align: center;background-color: DarkGray;\"><b>Nombre de tickets</b></td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: center;background-color: DarkGray;\">&nbsp;</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: DarkGray;\">Nouveaux</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: DarkGray;\">Retours</td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: NavajoWhite;\">R\351ception</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: NavajoWhite;\">" + tabResultatTab5[1][0] + "</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: NavajoWhite;\">" + tabResultatTab5[2][0] + "</td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: NavajoWhite;\">Pris en main</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: NavajoWhite;\">" + tabResultatTab5[3][0] + "</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: NavajoWhite;\">" + tabResultatTab5[4][0] + "</td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: NavajoWhite;\">En analyse</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: NavajoWhite;\">" + tabResultatTab5[5][0] + "</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: NavajoWhite;\">" + tabResultatTab5[6][0] + "</td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: NavajoWhite;\">Correction</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: NavajoWhite;\">" + tabResultatTab5[17][0] + "</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: NavajoWhite;\">" + tabResultatTab5[18][0] + "</td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: Yellow;\"><b>Total - Fiches en cours</b></td>";
		var1 = (parseInt(tabResultatTab5[1][0]) + parseInt(tabResultatTab5[3][0]) + parseInt(tabResultatTab5[5][0]) + parseInt(tabResultatTab5[17][0]));
		strRetour += "	  <td style=\"text-align: center;background-color: Yellow;\"><b>" + var1 + "</b></td>";
		var2 = (parseInt(tabResultatTab5[2][0]) + parseInt(tabResultatTab5[4][0]) + parseInt(tabResultatTab5[6][0]) + parseInt(tabResultatTab5[18][0]));
		strRetour += "	  <td style=\"text-align: center;background-color: Yellow;\"><b>" + var2 + "</b></td>";
		strRetour += "	</tr>";			
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: Yellow;\"><b>Stock SN3 de plus de 4 mois</b></td>";
		strRetour += "	  <td colspan=\"2\" style=\"text-align: center;background-color: Yellow;\"><b>" + tabResultatTab5[19][0] + "</b></td>";
		strRetour += "	</tr>";					
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: Yellow;\"><b>TOTAL SN3</b></td>";
		strRetour += "	  <td colspan=\"2\" style=\"text-align: center;background-color: Yellow;\"><b>" + (var1 + var2) + "</b></td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: DodgerBlue;\"><b>Fiches transmises hors SN3</b></td>";
		strRetour += "	  <td style=\"text-align: center;background-color: DodgerBlue;\"><b>" + tabResultatTab5[7][0] + "</b></td>";
		strRetour += "	  <td style=\"text-align: center;background-color: DodgerBlue;\"><b>" + tabResultatTab5[8][0] + "</b></td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: DodgerBlue;\"><b>TOTAL</b></td>";
		var3 = (parseInt(tabResultatTab5[7][0]) + parseInt(tabResultatTab5[8][0]));
		strRetour += "	  <td colspan=\"2\" style=\"text-align: center;background-color: DodgerBlue;\"><b>" + var3 + "</b></td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: darkorange;\"><b>TOTAL</b></td>";
		strRetour += "	  <td colspan=\"2\" style=\"text-align: center;background-color: darkorange;\"><b>" + (var1 + var2 + var3) + "</b></td>";
		strRetour += "	</tr>";
		strRetour += "  </tbody>";
		strRetour += "</table>";
		strRetour += "<br>";
		strRetour += "<br>";
		strRetour += "II - ENTRANT SORTANT DU JOUR<br>";
		strRetour += "<table style=\"text-align: left; width: 400;text-shadow: none;color: rgb(0, 0, 0);\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">";
		strRetour += "  <tbody>";
		strRetour += "	<tr>";
		strRetour += "	  <td colspan=\"3\" style=\"text-align: center;background-color: DarkGray;\"><b>Tickets Entrant/Sortant du jour</b></td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: center;background-color: DarkGray;\"><b>Statut</b></td>";
		strRetour += "	  <td colspan=\"2\" style=\"text-align: center;background-color: DarkGray;\"><b>Nombre de tickets</b></td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: center;background-color: DarkGray;\">&nbsp;</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: DarkGray;\">Nouveaux</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: DarkGray;\">Retours</td>";
		strRetour += "	</tr>";	
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: firebrick;\">Entrant</b></td>";
		strRetour += "	  <td style=\"text-align: center;background-color: firebrick;\">" + tabResultatTab5[9][0] + "</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: firebrick;\">" + tabResultatTab5[10][0] + "</td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: firebrick;\"><b>Total Entrant</b></td>";
		strRetour += "	  <td colspan=\"2\" style=\"text-align: center;background-color: firebrick;\"><b>" + (parseInt(tabResultatTab5[9][0]) + parseInt(tabResultatTab5[10][0])) + "</b></td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: Green;\">Sortant</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: Green;\">" + tabResultatTab5[11][0] + "</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: Green;\">" + tabResultatTab5[12][0] + "</td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: Green;\"><b>Total Sortant</b></td>";
		strRetour += "	  <td colspan=\"2\" style=\"text-align: center;background-color: Green;\"><b>" + (parseInt(tabResultatTab5[11][0]) + parseInt(tabResultatTab5[12][0])) + "</b></td>";
		strRetour += "	</tr>";
		strRetour += "  </tbody>";
		strRetour += "</table>";
		strRetour += "<br>";
		strRetour += "<br>";
		strRetour += "III - ENTRANT SORTANT DU MOIS<br>";
		strRetour += "<table style=\"text-align: left; width: 400;text-shadow: none;color: rgb(0, 0, 0);\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">";
		strRetour += "  <tbody>";
		strRetour += "	<tr>";
		strRetour += "	  <td colspan=\"3\" style=\"text-align: center;background-color: DarkGray;\"><b>Tickets Entrant/Sortant du mois</b></td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: center;background-color: DarkGray;\"><b>Statut</b></td>";
		strRetour += "	  <td colspan=\"2\" style=\"text-align: center;background-color: DarkGray;\"><b>Nombre de tickets</b></td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: center;background-color: DarkGray;\">&nbsp;</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: DarkGray;\">Nouveaux</td>";
		strRetour += "	  <td style=\"text-align: center;background-color: DarkGray;\">Retours</td>";
		strRetour += "	</tr>";	
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: firebrick;\"><b>Entrants du mois en cours</b></td>";
		strRetour += "	  <td style=\"text-align: center;background-color: firebrick;\"><b>" + tabResultatTab5[13][0] + "</b></td>";
		strRetour += "	  <td style=\"text-align: center;background-color: firebrick;\"><b>" + tabResultatTab5[14][0] + "</b></td>";
		strRetour += "	</tr>";				
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: Green;\"><b>Sortants du mois en cours</b></td>";
		strRetour += "	  <td style=\"text-align: center;background-color: Green;\"><b>" + tabResultatTab5[15][0] + "</b></td>";
		strRetour += "	  <td style=\"text-align: center;background-color: Green;\"><b>" + tabResultatTab5[16][0] + "</b></td>";
		strRetour += "	</tr>";
		strRetour += "  </tbody>";
		strRetour += "</table>";
		strRetour += "<br>";
		strRetour += "<table style=\"text-align: left; width: 400;text-shadow: none;color: rgb(0, 0, 0);\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">";
		strRetour += "  <tbody>";			
		strRetour += "	<tr>";
		strRetour += "	  <td style=\"text-align: left;background-color: darkorange;\"><b>Extrapolation de l'entrant \340 fin de mois</b></td>";
		strRetour += "	  <td style=\"text-align: center;background-color: darkorange;\"><b>" + (Math.round(parseInt(tabResultatTab5[13][0]) * parseFloat(tabResultatTab5[0][0]))) + "</b></td>";
		strRetour += "	</tr>";
		strRetour += "  </tbody>";
		strRetour += "</table>";
		
		return strRetour;
	}
	catch (er) {
		log(0, "ERROR(getHTMLTab5):" + er.message);
	}
}

///////////////////
//BLOCK FONCTIONS TECHNIQUES
///////////////////
function inputMoisEnCours(p_champs1, p_champs2) {
	try {
	
		var element1 = document.getElementById(p_champs1);
		var element2 = document.getElementById(p_champs2);
		
		var d = new Date();
		var dm = d.getMonth() + 1;
		var dan = d.getYear();
		if(dan < 999) dan+=1900;
		var nbjour = daysInMonth(dm,dan);
		
		element1.value = "01/"+pad2(dm)+"/"+dan;
		element2.value = nbjour+"/"+pad2(dm)+"/"+dan;
		
	}
	catch (er) {
		log(0, "ERROR(inputMoisEnCours):" + er.message);
	}
}

function inputMoisEnCoursRH(p_champs1, p_champs2) {
	try {
	
		var element1 = document.getElementById(p_champs1);
		var element2 = document.getElementById(p_champs2);
		
		var d = new Date();
		var dm = d.getMonth() + 1;
		var dan = d.getYear();
		var dd = d.getDate();
		if(dan < 999) dan+=1900;
		var nbjour = daysInMonth(dm,dan);
		if(dd == 1) {dd = 1;} else {dd -= 1;}
		
		element1.value = "01/"+pad2(dm)+"/"+dan;
		element2.value = pad2(dd)+"/"+pad2(dm)+"/"+dan;
		
	}
	catch (er) {
		log(0, "ERROR(inputMoisEnCours):" + er.message);
	}
}


/**
 * Appeller quant le worker à fini sa tâche
 * 
 */
function terminateMailSDWorker() {
    try {
        WorkerMailSD.terminate();
        $('#div_rappelSupDeb').html("Traitement annul&eacute;e");
    }
    catch (er) {
        log(0, "ERROR(terminateMailSDWorker):" + er.message);
    }
}

///////////////////
//BLOCK FONCTIONS AJAX JS/PHP/MYSQL
///////////////////
function getExpireToday() {
	try {
		var strResponse = "";
		var returns = new Array();
		var tempTab = new Array();
		var tempSubTab = new Array();

		xhr_object = new AJ();

		var url = "phpsql/mysql_getExpireToday.php?milis="+getMilise()+"&crtl=ok";

		xhr_object.open("GET", url, false);
		xhr_object.send(null);
		if (xhr_object.readyState == 4) {
			strResponse = xhr_object.responseText;
		} else {
			strResponse = "ERROR";
		}

		tempTab = strResponse.split("\n");

		for (var indice in tempTab) {
			tempSubTab = tempTab[indice].split("&");
			if (tempSubTab.length > 1) {
				returns[returns.length] = tempSubTab.slice(0, tempSubTab.length - 1);
			}
		}

		delete xhr_object;

		return returns;
	}
	catch (er) {
		log(0, "ERROR(getExpireToday):" + er.message);
	}
}
	
function getExpire20h() {
	try {
		var strResponse = "";
		var returns = new Array();
		var tempTab = new Array();
		var tempSubTab = new Array();

		xhr_object = new AJ();

		var url = "phpsql/mysql_getExpire20h.php?milis="+getMilise()+"&crtl=ok";

		xhr_object.open("GET", url, false);
		xhr_object.send(null);
		if (xhr_object.readyState == 4) {
			strResponse = xhr_object.responseText;
		} else {
			strResponse = "ERROR";
		}

		tempTab = strResponse.split("\n");

		for (var indice in tempTab) {
			tempSubTab = tempTab[indice].split("&");
			if (tempSubTab.length > 1) {
				returns[returns.length] = tempSubTab.slice(0, tempSubTab.length - 1);
			}
		}

		delete xhr_object;

		return returns;
	}
	catch (er) {
		log(0, "ERROR(getExpire20h):" + er.message);
	}
}

function getTabLive(p_strDate) {
	try {
		var strResponse = "";
		var returns = new Array();
		var tempTab = new Array();
		var tempSubTab = new Array();

		xhr_object = new AJ();

		var url = "phpsql/mysql_getLive.php?milis=" + getMilise() + "&date=" + p_strDate + "&crtl=ok";

		xhr_object.open("GET", url, false);
		xhr_object.send(null);
		if (xhr_object.readyState == 4) {
			strResponse = xhr_object.responseText;
		} else {
			strResponse = "ERROR";
		}

		tempTab = strResponse.split("\n");

		for (var indice in tempTab) {
			tempSubTab = tempTab[indice].split("&");
			if (tempSubTab.length > 1) {
				returns[returns.length] = tempSubTab.slice(0, tempSubTab.length - 1);
			}
		}

		delete xhr_object;

		return returns;
	}
	catch (er) {
		log(0, "ERROR(getTabLive):" + er.message);
	}
}

function getTabRapportRHuser(p_user) {
	try {
		var strResponse = "";
		var returns = new Array();
		var tempTab = new Array();
		var tempSubTab = new Array();

		xhr_object = new AJ();

		var url = "phpsql/mysql_getDataRapportRH2User.php?milis=" + getMilise() + "&user=" + p_user;

		xhr_object.open("GET", url, false);
		xhr_object.send(null);
		if (xhr_object.readyState == 4) {
			strResponse = xhr_object.responseText;
		} else {
			strResponse = "ERROR";
		}

		tempTab = strResponse.split("\n");

		for (var indice in tempTab) {
			tempSubTab = tempTab[indice].split("&");
			if (tempSubTab.length > 1) {
				returns[returns.length] = tempSubTab.slice(0, tempSubTab.length - 1);
			}
		}

		delete xhr_object;

		return returns;
	}
	catch (er) {
		log(0, "ERROR(getTabRapportRHuser):" + er.message);
	}
}

function AfficherExpiration(p_idtoc) {
    try {
        //1201836870
        var tabRetour = new Array();
        var strRetour = "";

        tabRetour = getInfoToc(p_idtoc);

        var prio = tabRetour[0][1];
        var statut = tabRetour[0][2];
        var ecoule = tabRetour[0][3];

        if ((statut == 'Support/D&eacute;blocage') || (statut == 'Correction') || (statut == 'Ferm&eacute;')) {
            strRetour = "Fig&eacute; par son statut(" + statut + ").";
        } else {
            var msg = getDateExpire(prio, statut, ecoule, null);

            strRetour = msg[0][0];
        }

        return strRetour;
    }
    catch (er) {
        strRetour = "Ticket non pr&eacute;sent dans la base au moment du scan (Voir en pied de page la date)";
        return strRetour;
        log(0, "ERROR(init):" + er.message);
    }
}

function getInfoToc(p_idtoc) {
    try {
        var strResponse = "";
        var returns = new Array();
        var tempTab = new Array();
        var tempSubTab = new Array();

        xhr_object = new AJ();

        var url = "phpsql/mysql_getInfoToc.php?milis=" + getMilise() + "&idtoc=" + p_idtoc;

        xhr_object.open("GET", url, false);
        xhr_object.send(null);
        if (xhr_object.readyState == 4) {
            strResponse = xhr_object.responseText;
        } else {
            strResponse = "ERROR";
        }

        tempTab = strResponse.split("\n");

        for (var indice in tempTab) {
            tempSubTab = tempTab[indice].split("&");
            if (tempSubTab.length > 1) {
                returns[returns.length] = tempSubTab.slice(0, tempSubTab.length - 1);
            }
        }

        delete xhr_object;

        return returns;
    }
    catch (er) {
        log(0, "ERROR(getTabIndic):" + er.message);
    }
}

function getDateExpire(p_priorite, p_statut, p_ecoule, p_lefttime) {
    try {
        var reste = 0;
		
		if((p_statut == 'Support/D&eacute;blocage')||(p_statut == 'Correction')||(p_statut == 'Ferm&eacute;')){
			return 'Fig&eacute; par son statut.';
		}else{
			if(p_lefttime == null){
			    if (p_priorite == 'P1-Bloquant') {
					reste = 480 - p_ecoule;
				}
				
				if(p_priorite == 'P2-Majeur'){
					reste = 960 - p_ecoule;
				}
				
				if((p_priorite == 'P3-Mineur')||(p_priorite == 'P4-Mineur')){
					reste = 2400 - p_ecoule;
				}
			}else{
				reste = p_lefttime;
			}
			
			var strResponse = "";
			var returns = new Array();
			var tempTab = new Array();
			var tempSubTab = new Array();

			xhr_object = new AJ();

			var url = "phpsql/mysql_getDateExpire.php?milis="+getMilise()+"&lefttime="+reste;

			xhr_object.open("GET", url, false);
			xhr_object.send(null);
			if (xhr_object.readyState == 4) {
				strResponse = xhr_object.responseText;
			} else {
				strResponse = "ERROR";
			}

			tempTab = strResponse.split("\n");

			for (var indice in tempTab) {
				tempSubTab = tempTab[indice].split("&");
				if (tempSubTab.length > 1) {
					returns[returns.length] = tempSubTab.slice(0, tempSubTab.length - 1);
				}
			}

			delete xhr_object;

			return returns;
		}
    }
    catch (er) {
        log(0, "ERROR(getDateExpire):" + er.message);
    }
}

function getTabUsers(date) {
    try {
        var strResponse = "";
        var returns = new Array();
        var tempTab = new Array();
        var tempSubTab = new Array();

        xhr_object = new AJ();

        var url = "phpsql/mysql_getUsers.php?milis="+getMilise()+"&date="+date+"&crtl=gard";

        xhr_object.open("GET", url, false);
        xhr_object.send(null);
        if (xhr_object.readyState == 4) {
            strResponse = xhr_object.responseText;
        } else {
            strResponse = "ERROR";
        }

        tempTab = strResponse.split("\n");

        for (var indice in tempTab) {
            tempSubTab = tempTab[indice].split("&");
            if (tempSubTab.length > 1) {
                if (tempSubTab[1] == "") {
                    tempSubTab[1] = tempSubTab[0];
                }
                returns[tempSubTab[0]] = tempSubTab.slice(0, tempSubTab.length - 1);
            }
        }

        delete xhr_object;

        return returns;
    }
    catch (er) {
        log(0, "ERROR(getTabUsers):" + er.message);
    }
}

function getTabUsers_lv1() {
    try {
        var strResponse = "";
        var returns = new Array();
        var tempTab = new Array();
        var tempSubTab = new Array();

        xhr_object = new AJ();

        var url = "phpsql/mysql_getUsers_lv1.php?milis="+getMilise()+"&crtl=gard";

        xhr_object.open("GET", url, false);
        xhr_object.send(null);
        if (xhr_object.readyState == 4) {
            strResponse = xhr_object.responseText;
        } else {
            strResponse = "ERROR";
        }

        tempTab = strResponse.split("\n");

        for (var indice in tempTab) {
            tempSubTab = tempTab[indice].split("&");
            if (tempSubTab.length > 1) {
                if (tempSubTab[1] == "") {
                    tempSubTab[1] = tempSubTab[0];
                }
                returns[tempSubTab[0]] = tempSubTab.slice(0, tempSubTab.length - 1);
            }
        }

        delete xhr_object;

        return returns;
    }
    catch (er) {
        log(0, "ERROR(getTabIndic):" + er.message);
    }
}

function getTabAvert() {
	try {
		var strResponse = "";
		var returns = new Array();
		var tempTab = new Array();
		var tempSubTab = new Array();

		xhr_object = new AJ();

		var url = "phpsql/mysql_getAvert.php?milis=" + getMilise() + "&crtl=ok";

		xhr_object.open("GET", url, false);
		xhr_object.send(null);
		if (xhr_object.readyState == 4) {
			strResponse = xhr_object.responseText;
		} else {
			strResponse = "ERROR";
		}

		tempTab = strResponse.split("\n");

		for (var indice in tempTab) {
			tempSubTab = tempTab[indice].split("&");
			if (tempSubTab.length > 1) {
				returns[returns.length] = tempSubTab.slice(0, tempSubTab.length - 1);
			}
		}

		delete xhr_object;

		return returns;
	}
	catch (er) {
		log(0, "ERROR(getTabAvert):" + er.message);
	}
}

/**
 * Récupération des données pour le rapport du stock
 * 
 */
function gettabResultatTab5() {
    try {
        var strResponse = "";
        var returns = new Array();
        var tempTab = new Array();
        var tempSubTab = new Array();

        xhr_object = new AJ();

        var url = "phpsql/mysql_getIndReport5.php?milis="+getMilise()+"&crtl=ok";

        xhr_object.open("GET", url, false);
        xhr_object.send(null);
        if (xhr_object.readyState == 4) {
            strResponse = xhr_object.responseText;
        } else {
            strResponse = "ERROR";
        }

        tempTab = strResponse.split("\n");

        for (var indice in tempTab) {
            tempSubTab = tempTab[indice].split("&");
            if (tempSubTab.length > 1) {
                returns[returns.length] = tempSubTab.slice(0, tempSubTab.length - 1);
            }
        }

        delete xhr_object;

        return returns;
    }
    catch (er) {
        log(0, "ERROR(gettabResultatTab5):" + er.message);
    }
}
 
/**
 * Traitement d'envoi des mails pour rappel support déblocage
 * 
 */
function traitementMailSD() {
    try {
        var strhtml = "";

        /* Vérifie si les Web Workers sont supportés */
        if (window.Worker) {
            strhtml += "<IMG SRC=\"API/img/loading.gif\" ALT=\"Chargement\" TITLE=\"Chargement\">";
            $('#div_rappelSupDeb').html(strhtml);

            WorkerMailSD = initWorker("WorkerEnvoiRappelSD.js", "traitementMailSD_retour");

            var json_param = {};

            WorkerMailSD.postMessage(new WorkerMessage('lancer', json_param)); 
        }
        else {
            $('#divEvolStock').html("Les Web Workers ne sont pas supportés par votre navigateur. Réessayez avec IE10 : <a href=\"http://ie.microsoft.com/testdrive\">téléchargez la dernière Platform Preview d'IE10 </a>");
        }

    }
    catch (er) {
        log(0, "ERROR(traitementMailSD):" + er.message);
    }
}

/**
 * Reception des messages retour du traitement d'envoi des rappels support déblocage
 * 
 * @param {string} p_message
 */
function traitementMailSD_retour(p_message) {
try {
    switch (p_message.cmd) {
        case 'avancement':
            var percent = p_message.parameter;
            $('#div_rappelSupDeb').html("<p>Avancement de la t&acirc;che...<strong><label id=\"labelProgress\">"+percent+"</label>%</strong><progress id=\"avancementProd\" value=\""+percent+"\" max=\"100\"></progress><img src=\"API/img/loading.gif\" alt=\"loading\" style=\"vertical-align:middle;\" /><br><a href=\"javascript:terminateMailSDWorker();\">Annuler</a></p>").trigger('create');
            break;
        case 'resultats':
            terminateWorker(WorkerMailSD);
        break;
        case 'stats':
            $('#div_rappelSupDeb').html("Dur&eacute;e du traitement en "+p_message.parameter+".");
        break;
        }
    }
    catch (er) {
        log(0, "ERROR(traitementMailSD_retour):" + er.message);
    }
}